package io.github.coderlaoliu.encrypt;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class Md5EncryptionStrategy implements EncryptionStrategy {
    @Override
    public String encrypt(String text, String key) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] hashBytes = md.digest(text.getBytes(StandardCharsets.UTF_8));
        StringBuilder sb = new StringBuilder();
        for (byte b : hashBytes) {
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    }

    @Override
    public String decrypt(String encryptedText, String key) throws Exception {
        return "MD5 does not support decryption.";
    }
}
